package com.agile.leetcode.string.stringjoin;

import java.util.StringJoiner;

/**
 * @Author ChenZhangKun
 * @Date 2020/11/19 13:19
 */
public class StringJionerDemo {
    public static void main(String[] args) {
        // 指定分隔符
        StringJoiner stringJoiner=new StringJoiner(",");
        stringJoiner.add("四川省")
                .add("自贡市")
                .add("大安区")
                .add("庙坝镇");
        System.out.println(stringJoiner.toString());
        // 输出结果 四川省,自贡市,大安区,庙坝镇
        // 指定分隔符和前缀后缀
        StringJoiner stringJoiner1=new StringJoiner(",","[","]");
        stringJoiner1.add("四川省")
                .add("自贡市")
                .add("大安区")
                .add("庙坝镇");
        // 输出结果 [四川省,自贡市,大安区,庙坝镇]
        System.out.println(stringJoiner1.toString());
        // 空值处理
        StringJoiner stringJoiner2=new StringJoiner(",");
        // 无结果
        System.out.println(stringJoiner2.toString());
        // 空值处理
        StringJoiner stringJoiner3=new StringJoiner(",","[","]");
        // 输出结果 []
        System.out.println(stringJoiner3.toString());
        // 设置空值
        StringJoiner stringJoiner4=new StringJoiner(",");
        stringJoiner4.setEmptyValue("czk");
        // 输出为czk
        System.out.println(stringJoiner4.toString());
        StringJoiner stringJoiner5=new StringJoiner(",","[","]");
        stringJoiner5.setEmptyValue("nzq");
        // 输出为nzq
        System.out.println(stringJoiner5.toString());
    }
}
